/***************************************************************
 *
 * (c) 2008 Markus Dittrich 
 *
 * This program is free software; you can redistribute it 
 * and/or modify it under the terms of the GNU General Public 
 * License Version 3 as published by the Free Software Foundation. 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License Version 3 for more details.
 *
 * You should have received a copy of the GNU General Public 
 * License along with this program; if not, write to the Free 
 * Software Foundation, Inc., 59 Temple Place - Suite 330, 
 * Boston, MA 02111-1307, USA.
 *
 ****************************************************************/

/* Qt includes */
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>

/* local includes */
#include "basic_definitions.h"
#include "popup_info_widget.h"
#include "utilities.h"

/* pull some symbols into namespace */
using std::vector;


/****************************************************************
 *
 * PlotinfoWidget provides a borderless info window for 
 * data points on the canvas
 *
 ***************************************************************/

//---------------------------------------------------------------
// constructor 
//---------------------------------------------------------------
PopUpInfoWidget::PopUpInfoWidget(QWidget* aParent, 
    Qt::WindowFlags type)
  :
    QWidget(aParent, type)
{
  setGeometry(x(),y(),100,80);
  setVisible(false);

  QPalette popupPalette;
  popupPalette.setColor(QPalette::Background, Qt::yellow);
  setPalette(popupPalette);
  setAutoFillBackground(true);

  QVBoxLayout* popUpLayout = new QVBoxLayout;

  NameLabel_ = new QLabel();

  QHBoxLayout* xCoordLayout = new QHBoxLayout;
  QLabel* xLabel = new QLabel(tr("X :  "));
  XPosLabel_ = new QLabel(tr("N/A"));
  xCoordLayout->addWidget(xLabel);
  xCoordLayout->addWidget(XPosLabel_);
  xCoordLayout->addStretch(1);
 
  QHBoxLayout* yCoordLayout = new QHBoxLayout;
  QLabel* yLabel = new QLabel(tr("Y :  "));
  YPosLabel_ = new QLabel(tr("N/A"));
  yCoordLayout->addWidget(yLabel);
  yCoordLayout->addWidget(YPosLabel_);
  yCoordLayout->addStretch(1);

  DataLabel_ = new QLabel();

  popUpLayout->addWidget(NameLabel_);
  popUpLayout->addLayout(xCoordLayout);
  popUpLayout->addLayout(yCoordLayout);
  popUpLayout->addStretch(1);
  popUpLayout->addWidget(DataLabel_);

  setLayout(popUpLayout);
}


/*****************************************************************
 *
 * public member functions
 *
 *****************************************************************/

//----------------------------------------------------------------
// set the content of the widget to be displayed
//----------------------------------------------------------------
void PopUpInfoWidget::set_content(const QString& name, 
    double xLabel, double yLabel, const vector<double>& dataVector)
{
  NameLabel_->setText("<b>" + strip_path(name) + "</b>");
  XPosLabel_->setText(QString::number(xLabel));
  YPosLabel_->setText(QString::number(yLabel));

  if ( !dataVector.empty() )
  {
    QString dataString(tr("<b>Data:</b><br>"));
    FOREACH(double dataItem, dataVector)
    {
      dataString += "-> ";
      dataString += QString::number(dataItem);
      dataString += "<br>";
    }

    DataLabel_->setText(dataString);
  }
  else
  {
    DataLabel_->clear();
  }
}


